#include<iostream>
#include<fstream>
#include<cmath>
#include<vector>
#include "../programming1/EquationSolver.h"
#include "BSpline_LinearSpline.h"
#include "BSpline_CubicSpline.h"
#include "BSpline_QuadraticSpline.h"
using namespace std;

class Func : public Function {
    public:
        virtual double operator () (const double& x)  {
            return 1 / (1 + x*x);
        }
         virtual double diff (const double& x)  {
            return -2*x / (1 + x*x) / (1 + x*x);
         }
        virtual double diff2 (const double& x) {
            return (-2 + 6*x*x) / (1 + x*x) / (1 + x*x) / (1 + x*x);
        }
} func;

int main() {
	LinearBSpline  linearBspline= LinearBSplineInterpolation( func, -5, 10);
	ofstream out1("Bspline_linear.csv");
	out1 << "x,y" << endl;
	for(int i = -4999; i <= 4999; ++ i) out1 << i * 0.001 << ',' << linearBspline.getValue(i * 0.001) << endl;

	CubicBSpline  natural_cubicBspline= CubicBSplineInterpolation ( func, -5, 10, "natural");
	ofstream out2("Bspline_cubic_natural.csv");
	out2 << "x,y" << endl;
	for(int i = -4999; i <= 4999; ++ i) out2 << i * 0.001 << ',' << natural_cubicBspline.getValue(i * 0.001) << endl;

	CubicBSpline complete_cubicBspline = CubicBSplineInterpolation ( func, -5, 10, "complete");
	ofstream out3("Bspline_cubic_complete.csv");
	out3 << "x,y" << endl;
	for(int i = -4999; i <= 4999; ++ i) out3 << i * 0.001 << ',' << complete_cubicBspline.getValue(i * 0.001) << endl;

	CubicBSpline ssd_cubicBspline = CubicBSplineInterpolation ( func, -5, 10, "ssd");
	ofstream out4("Bspline_cubic_ssd.csv");
	out4 << "x,y" << endl;
	for(int i = -4999; i <= 4999; ++ i) out4 << i * 0.001 << ',' << ssd_cubicBspline.getValue(i * 0.001) << endl;
	
	QuadraticBSpline quadraticBspline = QuadraticBSplineInterpolation ( func, -5, 10);
	ofstream out5("Bspline_quadratic.csv");
	out5 << "x,y" << endl;
	for(int i = -4999; i <= 4999; ++ i) out5 << i * 0.001 << ',' << quadraticBspline.getValue(i * 0.001) << endl;

}
